<?php

/***  DOCUMENTATION LAYER

	Greqo Atom Library

	Last Update: Mar 2007
	Author: Tom at klenwell@gmail.com

	FUNCTIONS
		greqo_atom_build_request_xml($title, $body, $published_uts=0, $content_type='html')
		greqo_atom_set_tag_published($uts)
		greqo_atom_set_datetime($uts=0, $timestamp=0)

  NOTES

______________________________________________________________________________*/


// greqo_build_post_xml
/*____________________________________________________________________________*/
function greqo_atom_build_request_xml($title, $body, $published_uts=0, $content_type='html') 
{
// *** DATA

	// Return
	$atom_data = '';


// *** MANIPULATE

	// escape html entities in title and content
	$title = greqo_escape_entities($title);
	$body = greqo_escape_entities($body);
	if ( !empty($published_uts) ) $_XML['published'] = greqo_atom_set_tag_published($published_uts);
	
	// create atom xml
	$atom_data = <<<XML
<entry xmlns="http://www.w3.org/2005/Atom">
	{$_XML['published']}
  <title type="$content_type">$title</title>
  <content type="$content_type">$body</content>
</entry>
XML;

// *** RETURN

	return $atom_data;
} 
/*____________________________________________________________________________*/


// greqo_atom_set_tag_published
/*____________________________________________________________________________*/
function greqo_atom_set_tag_published($uts) 
{
// *** DATA

	// Return
	$xml = '';


// *** MANIPULATE

	$datestamp = greqo_atom_set_datetime($uts);
	$xml = "<published>$datestamp</published>";

// *** RETURN

	return $xml;

} 
/*____________________________________________________________________________*/


// greqo_atom_set_datetime
/*____________________________________________________________________________*/
function greqo_atom_set_datetime($uts=0, $timestamp=0) 
{
// *** DATA

	// Return
	$datetime = '';


// *** MANIPULATE

	if ( !$uts ) $uts = time();
	$datestamp = date('Y-m-d\TH:i:s', $uts);
	$timezone = 'Z';
	$datetime = $datestamp . $timezone;

// *** RETURN

	return $datetime;

} 
/*____________________________________________________________________________*/


// Testbed
/*____________________________________________________________________________*/

if ( 0 )
{
	echo htmlspecialchars(greqo_atom_set_tag_published(time()));
	die;
}

/*____________________________________________________________________________*/

?>
